package com.xjj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjj.entity.Klass;
import com.xjj.entity.Manager;
import com.xjj.entity.School;
import com.xjj.entity.Student;
import com.xjj.mapper.ManagerMapper;
import com.xjj.service.ManagerService;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author sxy
 * @version 1.0
 * @date 2022/10/20 14:47
 */
@Service
public class ManagerServiceImpl extends ServiceImpl<ManagerMapper, Manager> implements ManagerService {
    @Resource
    private ManagerMapper managerMapper;

    public Manager getByAccount(String account) {
        return managerMapper.getByAccount(account);
    }
    @Override
    public void add(Manager manager){
        manager.setPassword(DigestUtils.md5Hex(manager.getPassword()));
        managerMapper.insert(manager);
    }

    @Override
    public Manager getManagerById(int id) {
       return managerMapper.getManagerById(id);
    }

    @Override
    public Page<Manager> getManager(Integer current) {
        Page<Manager> page = new Page<>(current , 10);
        QueryWrapper<Manager> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("*");
        page = managerMapper.selectPage(page,queryWrapper);
        return page;
    }

    @Override
    public List<Manager> getAllTeacherByKlassId(int klassId) {

        return managerMapper.getAllTeacherByKlassId(klassId);
    }


}
